#ifndef MSGSHOWAREA_H
#define MSGSHOWAREA_H

#include <QScrollArea>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QLabel>
#include <QFontMetrics>
#include <QPainter>
#include <QPainterPath>
#include <QTextLayout>
#include <QTextLine>
#include <QTextEdit>
#include "model/data.h"
#include "userinfowidget.h"

using model::MessageInfo;

///////////////////////////////
// 消息展示区
///////////////////////////////
class MsgShowArea : public QScrollArea
{
    Q_OBJECT
public:
    explicit MsgShowArea(QScrollArea *parent = nullptr);

    void addMsg(bool isLeft, const MessageInfo &msg);
    void addFrontMsg(bool isLeft, const MessageInfo &msg);
    void clear();
    void scrollToEnd();
private:
    QWidget *_container;
};

///////////////////////////////
// 一个消息元素
///////////////////////////////
class MessageItem : public QWidget
{
    Q_OBJECT
public:
    MessageItem(bool isLeft);

    static MessageItem* createMsgItem(bool isLeft, MessageInfo msg);

    static QWidget* makeStringMsgItem(bool isLeft, const QString &content);
    static QWidget* makeImageMsgItem();
    static QWidget* makeFileMsgItem();
    static QWidget* makeSpeechMsgItem();
private:
    bool _isLeft;
};

///////////////////////////////
// 文本消息正文部分
///////////////////////////////
class MsgContentLabel : public QWidget
{
    Q_OBJECT
public:
    MsgContentLabel(bool isLeft, const QString &text);

    void paintEvent(QPaintEvent *ev) override;
private:
    QLabel *_label;
    bool _isLeft;
    QString _text;
};

#endif // MSGSHOWAREA_H
